package 事件监听;

import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class Mouses extends JFrame implements MouseListener {
    //创建按钮对象
    JButton jbt1=new JButton("在这");
    public Mouses(){
        //设置界面的宽度和高度
        this.setSize(603,680);
        //设置界面标题
        this.setTitle("拼图小游戏");
        //设置界面置顶
        this.setAlwaysOnTop(true);
        //设置界面居中
        this.setLocationRelativeTo(null);
        //设置默认的关闭方式
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        //取消默认的剧中放置,只有取消了才会按照xy轴的形式添加组件
        this.setLayout(null);

        //给按钮设置位置和宽高
        jbt1.setBounds(100,0,100,50);
        //给按钮绑定鼠标事件
        jbt1.addMouseListener(this);

        //添加按钮到页面
        this.getContentPane().add(jbt1);
        //显示页面
        this.setVisible(true);
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        System.out.println("单击");
    }

    @Override
    public void mousePressed(MouseEvent e) {
        System.out.println("按下不松");
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        System.out.println("松开");
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        System.out.println("划入");
    }

    @Override
    public void mouseExited(MouseEvent e) {
        System.out.println("划出");
    }
}
